<html>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <link href="../style/main.css" type="text/css" rel="stylesheet">
        <link href="../style/item.css" type="text/css" rel="stylesheet">
        <script type="text/javascript" src="../script/jquery-1.8.2.js"></script>
</head>

<body>

 <header>
        <?php
        session_start();
        mysql_connect("localhost:3306", "root", "16886611");
        mysql_select_db("digitalsales");
        if(isset($_GET["action"])){
            if($_GET["action"]=="logout"){
               $_SESSION["username"]=NULL;
            }
        }
        if(!isset($_SESSION["username"])||$_SESSION["username"]==NULL){
        echo '<ul>
                <li id="login">
                  <p>Log in</p>
                </li>
                 <li>
                    <p><a href="../register/register.php">Register</a></p>
                  </li>
                </ul>';
        }else{
            echo '<ul>
                <li id="logout">
                  <p><a href="../index.php?action=logout">Log out</a></p>
                </li>
                 <li>
                    <p><a href="../myAccount/myAccount.php">My Account</a></p>
                  </li>
                  <li>
                    <p><a href="../myAccount/order.php">My Orders</a></p>
                  </li>
                  <li>
                    <p>Welcome back,'.$_SESSION["username"].'!</p>
                  </li>
                </ul>';
        }
        
        ?>
        </header>

<div id="product_title" class="MainPanel">

	<?php	
	$query=mysql_query("SELECT NAME FROM products WHERE PRODUCTID = ".$_GET['pid']."");
	$query_row=mysql_fetch_array($query);
	echo($query_row['NAME']);
	?>
<br />
</div>

<div id="product_photo" class="MainPanel">

	<?php	
	$query=mysql_query("SELECT PICTURE FROM products
	WHERE PRODUCTID = ".$_GET['pid']."");
	$query_row=mysql_fetch_array($query);
	?>
<img src=<?php echo "'../".$query_row['PICTURE']."'" ; ?> width="350px" height="350px">
<br />

</div>

<div id="product_description" class="MainPanel">

<form action="order_product.php" method="get">

<table>

<tr>
<th>Name</th>
<td>
	<?php	
	$query=mysql_query("SELECT NAME FROM products
	WHERE PRODUCTID = ".$_GET['pid']."");
	$query_row=mysql_fetch_array($query);
	echo($query_row['NAME']);
	?>
</td>
</tr>

<tr>
<th>Product Type</th>
<td>
	<?php	
	$query=mysql_query("SELECT PRODUCT_TYPE FROM products
	WHERE PRODUCTID = ".$_GET['pid']."");
	$query_row=mysql_fetch_array($query);
	echo($query_row['PRODUCT_TYPE']);
	?>
</td>
</tr>

<tr>
<th>Select Stores</th>
<td>
	<?php 
            echo '
	<Script language = "Javascript"> function refreshPrice(StoreId) {
		var address = window.location.href;
                addressarray = address.split("&");
		window.location.href = addressarray[0]+"&STOREID="+StoreId;
                
	}
	</Script>';
            echo '<input type="text" name="pid" value="'.$_GET["pid"].'" style="display:none"/>';
	
	$sql="SELECT S.STOREID, S.NAME FROM stores S, product_stores P
	where P.PID = ".$_GET['pid']." and S.STOREID = P.SID";
	$result=mysql_query($sql); 
	echo "<select style='width: 130pt;' name='STOREID'>";
	while( $row = mysql_fetch_array( $result)) {
          if ($row['STOREID']!= $_GET['STOREID'])
              echo "<option value='".$row["STOREID"]."' onclick ='refreshPrice(".$row["STOREID"].")' id = '".$row["STOREID"]."'>".$row["NAME"]."</option>";
	  else 
              echo "<option value='".$row["STOREID"]."' selected = true onclick ='refreshPrice(".$row["STOREID"].")' id = '".$row["STOREID"]."'>".$row["NAME"]."</option>";

              
        }
	echo "</select>";
        
        
	?>
</td>
</tr>

<tr>
<th>Price</th>
<td>
    <?php	
    $query=mysql_query("SELECT PRICE FROM product_stores
    WHERE PID = ".$_GET['pid']."
    and SID = ".$_GET['STOREID']."");
    $query_row=mysql_fetch_array($query);
    echo($query_row['PRICE']);
    ?>
</td>
</tr>

<tr>
<th>Inventory</th>
<td>
    <?php	
    $query=mysql_query("SELECT AMOUNT FROM product_stores
    WHERE PID = ".$_GET['pid']."
    and SID = ".$_GET['STOREID']."");
    $query_row=mysql_fetch_array($query);
    echo($query_row['AMOUNT']);
    ?>
</td>
</tr>

<tr>
<th>Description</th>
<td>
    <?php	
    $query=mysql_query("SELECT DESCRIPTION FROM products
    WHERE PRODUCTID = ".$_GET['pid']."");
    $query_row=mysql_fetch_array($query);
    echo($query_row["DESCRIPTION"]);
    ?>
</td>
</tr>

<tr>
<th>Quantity</th>
<td>
<input type="text" style="height: 26px;" name="quantity" size="22"/>    
</td>
</tr>

<tr>
<th></th>
<td><input type="submit" id="order" value="Order"></td>
</tr>

</table>
    
</form>
    
</div>

    <div id="product_sales" class="MainPanel">
    Product Sales<br />
    <img src="../product/line_chart.png" width="900px" height="300px" art="line chart">
    </div>

</body>

</html>